int umount_device(char* mountPath)
{
	int i, entry;
	for (entry = 0; entry < NUM_MOUNTS; entry++)
	{
		if (mountTable[entry].mountedInode != 0)
			if (strcmp(mountPath, mountTable[entry].mountedName) == 0)
				break;
	}
	
	if (entry >= NUM_MOUNTS)
	{
		printf("No device mounted at \"%s\"\n\n", mountPath);
		return -1;
	}
	
	/* Check if any processes using device */
	for (i = 0; i < NUM_FILE_DESC; i++)
	{
		if ((openFiles[i].memInode != 0) &&
			(openFiles[i].memInode->location.deviceHandle == mountTable[entry].handle))
		{
			printf("Cannot umount, there are open files on the device\n\n");
			return -1;
		}
	}
	
	/* Check if any files open on device */
	for (i = 0; i < NUM_PROCS; i++)
	{
		if ((procTable[i].status == PROC_BUSY) &&
			(procTable[i].cwd->location.deviceHandle == mountTable[entry].handle))
		{
			printf("Cannot umount, there are processes using the device\n\n");
			return -1;
		}
	}
	
	/* Check if filesystems mounted on the device */
	for (i = 0; i < NUM_MOUNTS; i++)
	{
		if ((mountTable[i].mountedInode != 0) && (i != entry) &&
			(mountTable[i].mountedInode->location.deviceHandle == mountTable[entry].handle))
		{
			printf("Cannot umount, there are filesystems mounted on the device\n\n");
			return -1;
		}
	}

	/* Finally umount the filesystem */
	close(mountTable[entry].handle);
	mountTable[entry].mountedInode->mounted = false;
	put_inode(mountTable[entry].mountedInode);
	mountTable[entry].mountedInode = 0;
}

int do_umount(char* dir)
{
	char fullPath[MAX_PATH_LENGTH];
	
	if (dir[0] != '/')
	{
		get_pwd_name(runningProc->cwd, fullPath);
		strcat(fullPath, dir);
	}
	else
		strcpy(fullPath, dir);
		
	if (fullPath[strlen(fullPath) - 1] != '/')
		strcat(fullPath, "/");
		
	return umount_device(fullPath);
}
